package com.ying.dogying.config;

import com.jagregory.shiro.freemarker.ShiroTags;
import com.ying.dogying.templates.ImHotsTemplate;
import com.ying.dogying.templates.ImPostTemplate;
import com.ying.dogying.templates.common.TimeAgoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class FreemarkerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    private ImPostTemplate imPostTemplate;

    @Autowired
    private ImHotsTemplate imHotsTemplate;

    /**
     * 添加自定义标签
     */
    @PostConstruct
    public void setUp() {
        configuration.setSharedVariable("posts", imPostTemplate);
        configuration.setSharedVariable("timeAgo", new TimeAgoUtils());
        configuration.setSharedVariable("hots", imHotsTemplate);
        // shiro 标签
        configuration.setSharedVariable("shiro", new ShiroTags());
    }
}
